package com.itheima;

import java.util.Scanner;

public class Test10 {
    public static void main(String[] args) {
        //完成双色球系统的开发
        int[] useNumbers = useSelectNumber();
        printNumbers(useNumbers);


        int[] luckyNumbers=creatNumber();
        printNumbers(luckyNumbers);

        checkWin(useNumbers,luckyNumbers);

    }
    //1.用户输入号码
    public static void printNumbers(int[] numbers) {
        System.out.print("[");
        for (int i = 0; i < numbers.length; i++) {
            System.out.print(i == numbers.length - 1 ? numbers[i] : numbers[i] + ", ");
        }
        System.out.println("]");
    }

    public static int[] useSelectNumber() {
        int[] numbers = new int[7];

        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < numbers.length - 1; i++) {
            while (true) {
                System.out.println("请您输入第" + (i + 1) + "个红球号码（1-33之间），不重复");
                int number = sc.nextInt();

                if (number < 1 || number > 33) {
                    System.out.println("输入的号码不合法，请重新输入");
                } else {
                    if (exist(numbers, number)) {
                        System.out.println("号码重复，请重新输入");

                    } else {
                        numbers[i] = number;
                        break;
                    }
                }
            }

        }
        while (true) {
            System.out.println("请您输入蓝球号码（1-16之间）");
            int number = sc.nextInt();
            if (number < 1 || number > 16) {
                System.out.println("输入的号码不合法，请重新输入");
            } else {
                numbers[6] = number;
                break;

            }
        }
        return numbers;

    }

    public static boolean exist(int[] numbers, int number) {
        for (int i = 0; i < numbers.length; i++) {
            if (numbers[i] == 0) {
                break;
            }
            if (numbers[i] == number) {
                return true;
            }
        }
        return false;
    }

    //2.随机生成中奖号码
    public static int[] creatNumber() {
        int[] numbers = new int[7];
        for (int i = 0; i < numbers.length - 1; i++) {
            while (true){
                int number = (int) (Math.random() * 33 + 1);//生成1-33之间的随机数
                if (!exist(numbers, number)) {
                    numbers[i] = number;
                    break;
                }
            }
        }

        numbers[6] = (int) (Math.random() * 16 + 1);//生成1-16之间的随机数
        return numbers;


    }

    //3.判断是否中奖
    public static void checkWin(int[] useNumbers, int[] luckyNumbers) {
        int redWin = 0;
        int blueWin = 0;
        for (int i = 0; i < useNumbers.length-1; i++) {
            for (int j = 0; j < luckyNumbers.length-1; j++) {
                if (useNumbers[i] == luckyNumbers[j]) {
                    redWin++;
                    break;
                }

            }

        }
        blueWin = useNumbers[6] == luckyNumbers[6]?1:0;
        System.out.println("您命中的红球个数为："+redWin);
        System.out.println("您命中的蓝球个数为："+blueWin);
        if (redWin == 6 && blueWin == 1) {
            System.out.println("恭喜你，中奖了1000万大奖");
        }else if (redWin == 6&& blueWin == 0) {
            System.out.println("恭喜你，中奖了500万大奖");
        }else if (redWin == 5 && blueWin == 1) {
            System.out.println("恭喜你，中奖了50万大奖");
        }else if (redWin == 5 && blueWin == 0) {
            System.out.println("恭喜你，中奖了10万大奖");
        }else if (redWin == 4 && blueWin == 1) {
            System.out.println("恭喜你，中奖了5000元");
        }else {
            System.out.println("很遗憾，你没有中奖");
        }

    }
}


